<template>
  <div class="app-container calendar-list-container">
    <el-button class="filter-item" type="primary" @click="cancel">返回</el-button>
    <el-button class="filter-item" type="primary" v-print="'#printBox'">打印</el-button>
    <div class="w-body info_form" id="printBox">
      <el-form :model="entity" ref="entity" label-width="80px" size="small">
        <el-row class="r-form-row">
          <el-col :span="24">
            <div class="view-title">发货单:{{entity.sendCode}}</div>
          </el-col>
        </el-row>
        <el-row class="r-form-row">
          <el-col :span="6" class="r-form-cell">
            <el-form-item label="订单号:" prop="orderNo">
              {{entity.orderNo}}
            </el-form-item>
          </el-col>
          <el-col :span="6" class="r-form-cell">
            <el-form-item label="客户名称:" prop="customerName">
              {{customerName}}
            </el-form-item>
          </el-col>
          <el-col :span="6" class="r-form-cell">
            <el-form-item label="仓库:" prop="warehouseCode">
              {{entity.warehouseName}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="数量:" prop="quantity">
              <span>{{entity.quantity}}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="r-form-row">
          <el-col :span="6" class="r-form-cell">
            <el-form-item label="总价:" prop="totalAmount">
              <span>{{entity.totalAmount}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6" class="r-form-cell">
            <el-form-item label="创建人:" prop="createUserName">
              <span>{{entity.createUserName}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6" class="r-form-cell">
            <el-form-item label="创建时间:" prop="createTime">
              <span>{{entity.createTime}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="总数:">
              <span>{{entity.total}}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="w-table">
              <grid gridTitle="物品信息" :columns="columns" :loading="false" ref="mainGrid" :pagination="false" :permissions="permissions" :multi="false" cellClassName="table-view-row"
                headerCellClassName="table-view-row"></grid>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import request from '@/router/axios'
import { Message, MessageBox } from 'element-ui'
import url from '@/const/apiURL'
import GridDialog from '@/components/GridDialog'
import grid from '@/components/Grid'
import { mapGetters } from 'vuex'

export default {
  components: { GridDialog, grid },
  data () {
    return {
      warehouseList: [],
      stockGoodsUrl: url.SEND_GOODS_LIST_URL,
      goodsUrl: url.SEND_OUT_GOODS_LIST_URL,
      orderNo: '',
      customerName: '',
      quantity: 0,
      entity: {
        orderNo: '',
        warehouseCode: '',
        goods: []
      },
      goodsQueryEntity: {},
      columns: [
        { label: this.global.modelName, width: 80, prop: 'goodsName', align: 'center' },
        { label: this.global.modelProp, width: 70, prop: 'modelProp', align: 'center' },
        { label: '物料名称', width: 200, prop: 'materialName', align: 'center' },
        { label: '客户型号', width: 80, prop: 'customerModelName', align: 'center' },
        // { label: '物料类型', width: 100, prop: 'materialTypeName', align: 'center' },
        { label: '单位', width: 60, prop: 'unit', align: 'center' },
        { label: '单价', width: 60, prop: 'price', align: 'center' },
        { label: '净重', width: 60, prop: 'goodsNetWeight', align: 'center' },
        { label: '毛重', width: 60, prop: 'goodsWeight', align: 'center' },
        { label: '顺序', width: 65, prop: 'indexSort', align: 'center' },
        { label: '数量', width: 80, prop: 'quantity', align: 'center' },
        { label: '匹数', width: 60, prop: 'total', align: 'center' },
        { label: '备注', width: 70, prop: '', align: 'center' }
      ]
    }
  },
  created () {
    this.orderNo = this.$route.query.orderNo
    this.entity.orderNo = this.$route.query.orderNo
    this.customerName = this.$route.query.customerName
    this.customerCode = this.$route.query.customerCode
    this.goodsQueryEntity.orderNo = this.$route.query.orderNo
    this.sendCode = this.$route.query.sendCode
    this.init()
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {
    init () {
      this.initWarehouse()
      this.initData()
    },
    cancel () {
      this.$router.push({ path: '/prod/order/send', query: { orderNo: this.orderNo } })
    },
    initWarehouse () {
      this.warehouseUrl().then(data => {
        if (data) {
          this.warehouseList = data
        }
      })
    },
    initData () {
      this.viewUrl(this.sendCode).then(data => {
        if (data) {
          this.entity = data
          data.goods.forEach(row => {
            row.code = row.linkCode
            this.$refs['mainGrid'].addRow(row)
          })
          this.quantity = data.goods.length
        }
      })
    },
    viewUrl (sendCode) {
      return request({
        url: url.SEND_VIEW_URL,
        method: 'post',
        data: { key: 'key' },
        params: { sendCode }
      })
    },
    warehouseUrl () {
      return request({
        url: url.WAREHOUSE_USABLE_URL,
        method: 'post',
        data: { key: 'key' }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.w-body {
  padding-top: 8px;
  width: 1024px;
}
.w-table {
  border: 1px solid #ebeef5;
}
.w-table-title {
  border: 1px solid #ebeef5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-all;
  line-height: 23px;
  display: inline-block;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  position: relative;
  vertical-align: middle;
  width: 100%;
  font-size: 14px;
  color: gray;
}

.view-title {
  width: 100%;
  height: 60px;
  font-size: 24px;
  text-align: center;
  font-weight: bold;
}

.grid-rq {
  border: 1px solid black !important;
}
</style>
